home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 2 / Atari Mega Archive CD - Volume 2.iso / minix / up1510b.tgz / up1510b / src / commands / shar.c < prev    next >
C/C++ Source or Header  |  1990-07-23  |  1KB  |  66 lines

  1. /* shar - make a shell archive        Author: Michiel Husijes */
  2.  
  3. #include <sys/types.h>
  4. #include <fcntl.h>
  5. #include <blocksize.h>
  6. #include <stdio.h>
  7.  
  8. #define IO_SIZE        (10 * BLOCK_SIZE)
  9.  
  10. char input[IO_SIZE];
  11. char output[IO_SIZE];
  12. int ind = 0;
  13.  
  14. main(argc, argv)
  15. int argc;
  16. register char *argv[];
  17. {
  18.   register int i;
  19.   int fd;
  20.  
  21.   for (i = 1; i < argc; i++) {
  22.     if ((fd = open(argv[i], O_RDONLY)) < 0) {
  23.         write(2, "Cannot open ", 12);
  24.         write(2, argv[i], strlen(argv[i]));
  25.         write(2, ".\n", 2);
  26.     } else {
  27.         print("echo x - ");
  28.         print(argv[i]);
  29.         print("\nsed '/^X/s///' > ");
  30.         print(argv[i]);
  31.         print(" << '/'\n");
  32.         cat(fd);
  33.     }
  34.   }
  35.   if (ind) write(1, output, ind);
  36.   exit(0);
  37. }
  38.  
  39. cat(fd)
  40. int fd;
  41. {
  42.   static char *current, *last;
  43.   register int r = 0;
  44.   register char *cur_pos = current;
  45.  
  46.   putchar('X');
  47.   for (;;) {
  48.     if (cur_pos == last) {
  49.         if ((r = read(fd, input, IO_SIZE)) <= 0) break;
  50.         last = &input[r];
  51.         cur_pos = input;
  52.     }
  53.     putchar(*cur_pos);
  54.     if (*cur_pos++ == '\n' && cur_pos != last) putchar('X');
  55.   }
  56.   print("/\n");
  57.   (void) close(fd);
  58.   current = cur_pos;
  59. }
  60.  
  61. print(str)
  62. register char *str;
  63. {
  64.   while (*str) putchar(*str++);
  65. }
  66.